﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BLL;
using Model;
using System.Data.SqlClient;
namespace UI
{
    public partial class 系统设置 : Form
    {
        public 系统设置()
        {
            InitializeComponent();
        }
        //加载事件
        private void 系统设置_Load(object sender, EventArgs e)
        {
            this.listView1.Items.Clear();
            this.listView2.Items.Clear();
            //查询操作员
            SqlDataReader dr = 系统设置BLL.ChaSuoYou();
            while (dr.Read())
            {
                string id = dr[0].ToString();
                string name = dr[1].ToString();
                string Pwd = dr[2].ToString();
                ListViewItem li = new ListViewItem(id);
                li.SubItems.Add(name);
                li.Tag = Pwd;
                this.listView1.Items.Add(li);
            }
            
            
            //查询会员
            SqlDataReader dd = 系统设置BLL.CHaSuoYouVIP();
            while (dd.Read())
            {
                string VGName=dd["VGName"].ToString();
                string VGDiscount = dd["VGDiscount"].ToString();
                ListViewItem la = new ListViewItem(VGName);
                la.SubItems.Add(VGDiscount);
                this.listView2.Items.Add(la);
            }
            
        }
        
        private void btnAddCuoZuo_Click(object sender, EventArgs e)
        {
            系统添加 f = new 系统添加();
            f.Show();
            this.Close();
        }

        private void btnUpdCaoZuo_Click(object sender, EventArgs e)
        {
            try
            {
                Admins.UserID = int.Parse(this.listView1.SelectedItems[0].SubItems[0].Text);
                Admins.UserCompellation = this.listView1.SelectedItems[0].SubItems[1].Text;
                Admins.UserPwd = this.listView1.SelectedItems[0].Tag.ToString();
                //MessageBox.Show(修改操作员Model.id);
                系统修改 f = new 系统修改();
                f.Show();
                this.Close();
            }
            catch (Exception)
            {

                MessageBox.Show("请选中一行");
            }
         
        }

        private void btnDelCaoZuo_Click(object sender, EventArgs e)
        {
            try
            {
                Admins.UserID = int.Parse(this.listView1.SelectedItems[0].SubItems[0].Text);
                int count = 系统设置BLL.Del();
                if (count > 0)
                {
                    MessageBox.Show("删除成功");
                    系统设置_Load(null, null);
                }
                else
                {
                    MessageBox.Show("删除失败");
                }
            }
            catch (Exception)
            {

                MessageBox.Show("请选中一行");
            }
        }
    }
}
